package com.example.flowstatedemo

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow

class   MainViewModel : ViewModel() {
    private val mLiveData = MutableLiveData("Hello World")
    val liveData:LiveData<String> = mLiveData

    private val mStateFlow = MutableStateFlow("Hello World")
    val stateFlow = mStateFlow.asStateFlow()

    private val mSharedFlow = MutableSharedFlow<String>()
    val sharedFlow = mSharedFlow.asSharedFlow()

    fun triggerLiveData(){
        mLiveData.value = "liveData"
    }

    fun triggerStateFlowData(){
        mStateFlow.value = "StateFlow"
    }

    suspend fun triggerSharedFlowData(){
        mSharedFlow.emit("SharedFlow")
    }
}